<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>state</title>
  </head>
  <body>
    <div id="test"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
      // 注意：
      // 1. state为实例属性，所以是用在类式组件中

      // 创建 Weather 组件
      class Weather extends React.Component {
        constructor(props) {
          super(props)
          // this.isHot = false // 这样写会直接在当前实例对象上添加该属性
          this.state = {
            isHot: true
          }
        }

        render() {
          console.log(this)
          const { isHot } = this.state
          return <p>今天天气很{isHot ? '炎热' : '清爽'}</p>
        }
      }

      ReactDOM.render(<Weather />, document.getElementById('test'))
    </script>
  </body>
</html>
